package com.aust.lambda;

/**
 * 推导lambda表达式
 */
public class TestLambda {

    /**
     * 静态内部类
     */
    static class LikeS implements ILike {
        @Override
        public void lambda() {
            System.out.println("I like lambda static");
        }
    }

    public static void main(String[] args) {
        ILike like = new Like();
        like.lambda();

        ILike likeS = new LikeS();
        likeS.lambda();

        /**
         * 局部内部类
         */
        class LikeL implements ILike {
            @Override
            public void lambda() {
                System.out.println("I like lambda local");
            }
        }
        ILike likeL = new LikeL();
        likeL.lambda();

        /**
         * 匿名内部类
         */
        ILike likeI = new ILike() {
            @Override
            public void lambda() {
                System.out.println("I like lambda anonymous");
            }
        };
        likeI.lambda();

        /**
         * lambda简化
         */
        ILike likeLambda = () -> {
            System.out.println("I like lambda lambda");
        };
        likeLambda.lambda();

    }
}

/**
 * 函数式接口
 */
@FunctionalInterface
interface ILike {
    void lambda();
}

/**
 * ILike实现类
 */
class Like implements ILike {
    @Override
    public void lambda() {
        System.out.println("I like lambda");
    }
}